package com.suxin.ratelimit.repository;

import com.suxin.ratelimit.Rate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tang
 * @classname InMemoryRateLimiter
 * @description [  ]
 * @date 2021/7/14 22:47
 */
public class InMemoryRateLimiter extends AbstractRateLimiter {

    private Map<String, Rate> cacheMap = new HashMap<>(16);

    public InMemoryRateLimiter() {
    }

    @Override
    public Rate getRate(String key) {
        return cacheMap.get(key);
    }

    @Override
    public void saveRate(Rate rate) {
        cacheMap.put(rate.getKey(), rate);
    }
}